// DriveNotes. Copyright (c) 2011, Andrei Senchuk. All rights reserved.
package net.taviscaron.drivenotes.server.model.dao.impl;

import java.util.List;
import net.taviscaron.drivenotes.server.model.dao.ServiceDAO;
import net.taviscaron.drivenotes.shared.model.entity.Car;
import net.taviscaron.drivenotes.shared.model.entity.Service;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * Service DAO Impl
 * @author Andrei Senchuk
 */
public class ServiceDAOImpl extends HibernateDaoSupport implements ServiceDAO {

    public Service findById(Long id) {
        return getHibernateTemplate().load(Service.class, id);
    }

    public void save(Service service) {
        getHibernateTemplate().saveOrUpdate(service);
    }

    public void remove(Service obj) {
        getHibernateTemplate().delete(obj);
    }

    @SuppressWarnings("unchecked")
    public List<Service> findServicesByCar(Car car) {
        return getHibernateTemplate().find("from Service service where car = ? order by service.date desc", car);
    }
}
